package editAir.editContent
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.geom.Point;

	public class ListTitleBar extends MovieClip
	{
		private var _tray_title:MovieClip;
		private var _mouseDown:Boolean=false;
		private var _lastMousePoint:Point=new Point;
		private var _lastObjectPosition:Point=new Point;

		public function ListTitleBar()
		{
			super();
			addPics();
			addEvents();
		}

		private function addEvents():void
		{
			this.addEventListener(MouseEvent.MOUSE_DOWN, titleMouseDown)
			ModelUiManege.stage.addEventListener(MouseEvent.MOUSE_MOVE, stageMouseMove)
			ModelUiManege.stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp)
			_tray_title.c1.addEventListener(MouseEvent.MOUSE_DOWN, c1titleMouseDown)
		}

		public function del_folder():void
		{
			ModelUiManege.fileList.del_folder();
		}

		public function add_folder():void
		{
            ModelUiManege.fileList.add_folder();
		}

		private function c1titleMouseDown(event:MouseEvent):void
		{
			if (_tray_title.c1.currentFrame == 1)
			{
				_tray_title.c1.gotoAndPlay(2);
			}
			else
			{
				_tray_title.c1.gotoAndStop(1);
			}
		}

		protected function stageMouseUp(event:MouseEvent):void
		{
			_mouseDown=false;
		}

		protected function stageMouseMove(event:MouseEvent):void
		{
			if (_mouseDown)
			{
				Object(parent.parent).x=_lastObjectPosition.x + ((ModelUiManege.stage.mouseX - _lastMousePoint.x));
				Object(parent.parent).y=_lastObjectPosition.y + ((ModelUiManege.stage.mouseY - _lastMousePoint.y));
			}
		}

		protected function titleMouseDown(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			_mouseDown=true;
			_lastObjectPosition.x=Object(parent.parent).x
			_lastObjectPosition.y=Object(parent.parent).y
			_lastMousePoint.x=ModelUiManege.stage.mouseX
			_lastMousePoint.y=ModelUiManege.stage.mouseY
		}

		private function addPics():void
		{

			_tray_title=ModelUiManege.getClass("tray_title");
			addChild(_tray_title);
		}
	}
}
